package com.warm.demo.mf.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.R;
import com.warm.demo.mf.api.dto.TestMaterDto;
import com.warm.demo.mf.api.vo.TestMaterVo;
import com.warm.demo.mf.service.ITestMaterService;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.mf.core.domain.QueryParam;
import com.warm.mf.core.page.TableDataInfo;
import com.warm.mybatis.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;

/**
 * 主子演示Controller
 *
 * @author warm
 */
@Api(value = "主子演示控制器", tags = {"主子演示管理"})
@Valid
@Controller
@Mapping("/test/mater")
public class TestMaterController extends BaseController {
    @Inject
    private ITestMaterService testMaterService;

    /**
     * 分页查询主子演示列表
     */
    @ApiOperation("分页查询主子演示列表")
    @SaCheckPermission("test:mater:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<TestMaterVo> list(QueryParam queryParam, TestMaterDto dto) {
        return testMaterService.selectPage(queryParam, dto);
    }


    /**
     * 获取主子演示详细信息
     */
    @ApiOperation("获取主子演示详细信息")
    @SaCheckPermission("test:mater:query")
    @Get
    @Mapping(value = "/{id}")
    public R<TestMaterVo> getInfo(Long id) {
        return R.ok(testMaterService.selectById(id));
    }

    /**
     * 新增主子演示
     */
    @ApiOperation("新增主子演示")
    @SaCheckPermission("test:mater:add")
    @Log(title = "主子演示", businessType = BusinessType.INSERT)
    @Post
    @Mapping
    public R<Void> add(TestMaterDto dto) {
        return toR(testMaterService.insertByDto(dto));
    }

    /**
     * 修改主子演示
     */
    @ApiOperation("修改主子演示")
    @SaCheckPermission("test:mater:edit")
    @Log(title = "主子演示", businessType = BusinessType.UPDATE)
    @Put
    @Mapping
    public R<Void> edit(TestMaterDto dto) {
        return toR(testMaterService.updateByDto(dto));
    }

    /**
     * 删除主子演示
     */
    @ApiOperation("删除主子演示")
    @SaCheckPermission("test:mater:remove")
    @Log(title = "主子演示", businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{ids}")
    public R<Void> remove(Long[] ids) {
        return toR(testMaterService.deleteByIds(ids));
    }
}
